package com.easy.easy.Controller;

import com.easy.easy.Service.LoginService;
import com.easy.easy.bean.Admin;
import com.easy.easy.bean.User;
import com.easy.easy.util.SYS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @Autowired
    LoginService loginService;


    @RequestMapping("shopping/dologin")
    @ResponseBody
public String shoppingLogin(User user, HttpSession session) {
        System.out.println(111);
        //执行登录业务
        User u = loginService.dologin(user);
        if (u != null) {
            //记录登陆状态
            session.setAttribute(SYS.SHOPPING_LOGIN_USER, u);
            return "success";
        } else {
            return "fail";
        }
    }
@RequestMapping("system/doadminlogin")
@ResponseBody
    public String systemLogin(HttpSession session, Admin admin) {
    System.out.println("doadminlogin");
        Admin a=loginService.doadminlogin(admin);
        if (a != null) {
            session.setAttribute(SYS.SYSTEM_LOGIN_ADMIN, a);
            return "success";
        }
     return "fail";
    }
}
